//
//  FirstViewController.m
//  FitnessRecord
//
//  Created by William Cai on 15/4/2.
//  Copyright (c) 2015年 William Cai. All rights reserved.
//

#import "FirstViewController.h"

@interface FirstViewController ()

@property (weak, nonatomic) IBOutlet UITextField *Height;
@property (weak, nonatomic) IBOutlet UITextField *Weight;
@property (weak, nonatomic) IBOutlet UILabel *Result;

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)ShowResult:(id)sender {
    float h = _Height.text.floatValue / 100;
    float w = _Weight.text.floatValue;
    
    float bmi = w / ( h * h );
    NSLog(@"bmi = %f", bmi);
    
    if ( bmi >= 25 ) {
        _Result.text = @"肥胖";
        _Result.backgroundColor = [UIColor redColor];
    } else if ( bmi < 18.5 ) {
        _Result.text = @"偏瘦";
        _Result.backgroundColor = [UIColor yellowColor];
    } else {
        _Result.text = @"标准";
        _Result.backgroundColor = [UIColor greenColor];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end